cmake_minimum_required(VERSION 3.0.2)
project(reivoice_ai)

## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)

execute_process(
  COMMAND whoami
  OUTPUT_VARIABLE USERNAME
  OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(AIUI_FILE_PATH "/home/${USERNAME}/.ros/REIAIUI")
if(EXISTS "${AIUI_FILE_PATH}")
  message("AIUI config file exists")
else()
  add_custom_command(OUTPUT COPY_SOURCE_config 
      COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/REIAIUI /home/${USERNAME}/.ros/REIAIUI)
  add_custom_target(Copy_config ALL DEPENDS COPY_SOURCE_config)
endif()

find_package(catkin REQUIRED COMPONENTS
  actionlib
  message_generation
  move_base_msgs
  roscpp
  rospy
  std_msgs
  std_srvs
)


## Generate messages in the 'msg' folder
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )

## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )

## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )
generate_messages(
  DEPENDENCIES
  std_msgs
)

catkin_package(
 CATKIN_DEPENDS message_runtime
 DEPENDS PortAudio
)

include_directories(
  include/reinovo_ai_voice
  src/rei_aiui
  src/jsoncpp
  src/utils
  ${catkin_INCLUDE_DIRS}
)

set(SystemPlatform "x86_64")
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
  set(SystemPlatform "x86_64")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
  set(SystemPlatform "aarch64")
endif()
link_directories(
  libs/${SystemPlatform}
  ${catkin_LIB_DIRS}
)

file(GLOB_RECURSE JSONCPP_FILE
        "src/jsoncpp/*.cpp")

file(GLOB_RECURSE UTILS_FILE
        "src/utils/*.cpp")

# add_library(reinovo_voice
#   ${JSONCPP_FILE}
#   ${UTILS_FILE}
# )

# target_link_libraries(reinovo_voice
#   ${catkin_LIBRARIES}
  
# )

# 输出收集到的源文件列表
# message(STATUS "SOURCE_FILE 包含的文件: ${SOURCE_FILE}")



add_executable(voice_aiui_node 
  ${JSONCPP_FILE}
  ${UTILS_FILE}
  src/test/voice_aiui_node.cpp
  # src/rei_aiui/voice_aiui.cpp
)
add_dependencies(voice_aiui_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(voice_aiui_node
  ${catkin_LIBRARIES}
  aiui
)

add_executable(voice_record_node
  src/reiaudio_record/voice_record_node.cpp
)
add_dependencies(voice_record_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(voice_record_node
  ${catkin_LIBRARIES}
  portaudio  # PortAudio库
  pthread
  m
)

install(TARGETS voice_aiui_node
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

foreach(dir launch srv REIAIUI)
	install(DIRECTORY ${dir}/
		DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/${dir})
endforeach(dir)

foreach(dir libs/${SystemPlatform}/)
	install(DIRECTORY ${dir}/
		DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
endforeach(dir)

install(DIRECTORY include/${PROJECT_NAME}/
  DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  FILES_MATCHING PATTERN "*.h"
  PATTERN ".svn" EXCLUDE
)

install(FILES
  README.txt
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)